package com.qfedu.buy.server.listener;

import com.qfedu.buy.common.config.RabbitMQConstantConfig;
import com.qfedu.buy.common.config.RedisKeyConfig;
import com.qfedu.buy.common.util.RedissonUtil;
import com.qfedu.buy.server.config.RabbimqConfig;
import com.qfedu.buy.server.entity.SkillOrder;
import com.qfedu.buy.server.service.intf.SkillOrderService;
import org.springframework.amqp.rabbit.annotation.RabbitHandler;
import org.springframework.amqp.rabbit.annotation.RabbitListener;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Component;

/**
 * @program: NeighborBuy
 * @description:
 * @author: Feri(邢朋辉)
 * @create: 2021-02-05 14:52
 */
@RabbitListener(queues = RabbitMQConstantConfig.QUEUE_SKILL_ORDER)
@Component
public class SkillOrderListener {
    @Autowired
    private SkillOrderService service;
    @RabbitHandler
    public void sync(long oid){
        if(oid>0){
            //实现数据同步
            SkillOrder order= (SkillOrder) RedissonUtil.getObj(RedisKeyConfig.SKILL_ORDER+oid);
            if(service.save(order)){
                //删除Redis
                RedissonUtil.delKeys(RedisKeyConfig.SKILL_ORDER+oid);
            }
        }
    }
}
